<template>
  <!--下方的缩略图-->
  <div class="specScroll">
    <!--左按钮-->
    <a class="prev" @click="pervImg">&lt;</a>
    <!-- 中间可滑动区域 -->
    <div class="items">
      <div class="itemsCon" :style="{ transform: 'translateX(' + moveImg * -76 + 'px)' }">
        <!-- :style="{ transform: moveImg * -76 + 'px' }" -->
        <img v-for="(img, index) in skuInfo.skuImageList" :key="img.id" :class="{ active: imgVal === index }" :src="img.imgUrl" @mouseenter="hoverImg(index)" />
      </div>
    </div>
    <!--右按钮-->
    <a class="next" @click="nextImg">&gt;</a>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'ImageList',
  data() {
    return {
      // 移动索引
      moveImg: 0,
      // 滑动索引
      imgVal: 0,
    }
  },
  computed: {
    ...mapGetters('detail', ['skuInfo']),
  },
  methods: {
    nextImg() {
      if (this.moveImg >= this.skuInfo.skuImageList.length - 5) return
      this.moveImg++
    },
    pervImg() {
      if (this.moveImg <= 0) return
      this.moveImg--
    },
    hoverImg(index) {
      this.imgVal = index
      this.$store.commit('detail/GETBIGIMG', this.skuInfo.skuImageList[index].imgUrl)
    },
  },
}
</script>

<style lang="scss" scoped>
.specScroll {
  margin-top: 5px;
  width: 400px;
  overflow: hidden;
  .prev,
  .next {
    text-align: center;
    width: 10px;
    height: 54px;
    line-height: 54px;
    border: 1px solid #ccc;
    background: #ebebeb;
    cursor: pointer;
    user-select: none;
  }
  .prev {
    float: left;
    margin-right: 4px;
  }
  .next {
    float: right;
  }
  .items {
    float: left;
    position: relative;
    width: 372px;
    height: 56px;
    overflow: hidden;
    .itemsCon {
      position: absolute;
      width: 9999px;
      height: 56px;
      left: 0;
      transition: all 0.5s;
      img {
        float: left;
        text-align: center;
        border: 1px solid #ccc;
        padding: 2px;
        width: 50px;
        height: 50px;
        margin-right: 20px;
      }
      .active {
        border: 2px solid red;
        padding: 1px;
      }
    }
  }
}
</style>
